package com.hbnu.service.impl;
import com.hbnu.dao.DoorMapper;
import com.hbnu.pojo.Door;
import com.hbnu.service.DoorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class DoorServiceImpl implements DoorService {

    @Autowired
    private DoorMapper doorMapper;

    // 1.查询所有门店信息  @return List<Door>
    @Override
    public List<Door> findAll() {
        // 1.调用DoorMapper的findAll方法，查询所有门店信息
        return  doorMapper.findAll();
    }

    // 2.新增门店信息
    @Override
    public void addDoor(Door door) {
        // 调用DoorMapper的addDoor方法，新增门店信息
        doorMapper.addDoor(door);
    }

    // 3.删除门店信息

    @Override
    public void deleteById(Integer id) {
        // 检查该门店是否有相关订单
        int orderCount = doorMapper.countOrdersByDoorId(id);
        if (orderCount > 0) {
            throw new RuntimeException("该门店有未处理的订单，请先将订单处理后再进行门店删除！");
        }
        // 调用DoorMapper的deleteById方法，根据id删除指定的门店信息
        doorMapper.deleteById(id);
    }


    // 4.根据id查询门店信息
    @Override
    public Door findById(Integer id) {
        // 调用DoorMapper的findById方法，根据id查询门店信息
        Door door = doorMapper.findById(id);
        return door;
    }

    // 5.根据id更新门店信息
    @Override
    public void updateById(Door door) {
        // 调用DoorMapper的updateById方法，根据id更新门店信息
        doorMapper.updateById(door);
    }
}
